//bange_main.cpp
//Copyright (C) 2010-2011 Oscar (.teri) Triano

//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include <iostream>
#include <cstring>
#include <physfs.h>
#include <chipmunk/chipmunk.h>
#include <bange_box.hpp>

using namespace std;

int main(int argc, char* argv[]){
	if(!PHYSFS_init(argv[0])){
		cout << "bange: physfs can't initialize: " << PHYSFS_getLastError() << endl;
		EXIT_FAILURE;}
	cpInitChipmunk();
	bange::box box;
	bool init = false;
	/*
	cpVect test = {1, 1};
	test = !test;
	cout << "test x: " << test.x << endl;
	cout << "test x: " << test.y << endl;
	*/
    if (box.Error() == true){
		return EXIT_FAILURE;}
	if (argc >= 2){
		init = box.InitFromConsole(argv[1]);}
	else{
		init = box.InitFromDesktop();}
	if(init){
		box.Run();}
	if (!PHYSFS_deinit()){
		cout << "bange: physfs failed to deinitialize??: " << PHYSFS_getLastError() << endl;
		return EXIT_FAILURE;}
    return EXIT_SUCCESS;
}
